<template>

  <div class="app-container">
    <el-row>
      <el-col :span="4" >
        <el-form :model="decidqueryParams"  ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="50px">
          <el-form-item label="" prop="decid">
            <el-input
              v-model="decidqueryParams.decid"
              placeholder="请输入堆垛机编号"
              clearable
              @keyup.enter.native="handleQuery2"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery2">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery2">重置</el-button>
          </el-form-item>
        </el-form>
        <!--            <el-form-item label="状态" prop="STATUS">-->
        <!--              <el-select v-model="queryParams.STATUS" placeholder="请选择状态" clearable>-->
        <!--                <el-option-->
        <!--                  v-for="dict in dict.type.status"-->
        <!--                  :key="dict.value"-->
        <!--                  :label="dict.label"-->
        <!--                  :value="dict.value"-->
        <!--                />-->
        <!--              </el-select>-->
        <!--            </el-form-item>-->
        <el-card style="margin-top: 20px">
          <el-table v-loading="loading" height="880px" :data="delDecnameList" @cell-dblclick="handleCellDblClick">
                    @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="堆垛机编号" align="center" prop="decid"/>
            <el-table-column label="状态" align="center" prop="sts">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.status" :value="scope.row.sts"/>
              </template>
            </el-table-column>
          </el-table>
        </el-card>

      </el-col>

      <el-col :span="20">

        <el-row :gutter="10" class="mb8">

          <!--                  <el-col :span="1.5">-->
          <!--                    <el-button-->
          <!--                      type="primary"-->
          <!--                      plain-->
          <!--                      icon="el-icon-plus"-->
          <!--                      size="mini"-->
          <!--                      @click="handleAdd"-->
          <!--                      v-hasPermi="['system:LOCATION:add']"-->
          <!--                    >新增-->
          <!--                    </el-button>-->
          <!--                  </el-col>-->
          <!--                  <el-col :span="1.5">-->
          <!--                    <el-button-->
          <!--                      type="success"-->
          <!--                      plain-->
          <!--                      icon="el-icon-edit"-->
          <!--                      size="mini"-->
          <!--                      :disabled="single"-->
          <!--                      @click="handleUpdate"-->
          <!--                      v-hasPermi="['system:LOCATION:edit']"-->
          <!--                    >修改-->
          <!--                    </el-button>-->
          <!--                  </el-col>-->
          <!--                  <el-col :span="1.5">-->
          <!--                    <el-button-->
          <!--                      type="danger"-->
          <!--                      plain-->
          <!--                      icon="el-icon-delete"-->
          <!--                      size="mini"-->
          <!--                      :disabled="multiple"-->
          <!--                      @click="handleDelete"-->
          <!--                      v-hasPermi="['system:LOCATION:remove']"-->
          <!--                    >删除-->
          <!--                    </el-button>-->
          <!--                  </el-col>-->
          <!--              <el-col :span="1.5">-->
          <!--                <el-button-->
          <!--                  type="warning"-->
          <!--                  plain-->
          <!--                  icon="el-icon-download"-->
          <!--                  size="mini"-->
          <!--                  @click="handleExport"-->
          <!--                  v-hasPermi="['system:LOCATION:export']"-->
          <!--                >导出-->
          <!--                </el-button>-->
          <!--              </el-col>-->
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                   label-width="100px">
            <el-form-item label="库位编号" prop="locationId">
              <el-input
                v-model="queryParams.locationId"
                placeholder="请输入库位编号"
                clearable
                @keyup.enter.native="handleQuery1"
              />
            </el-form-item>

            <el-form-item label="状态" prop="STATUS">
              <el-select v-model="queryParams.STATUS" placeholder="请选择状态" clearable>
                <el-option
                  v-for="dict in dict.type.kw_sts"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery1">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery1">重置</el-button>

            </el-form-item>
            <div class="float-right-container">
              <div class="chart-container">
                <div class="bar-container">
                  <div class="bar" style="background-color: #a4f3b7; height: 20px;"></div>
                  <div class="label">可入库</div>
                </div>
                <div class="bar-container">
                  <div class="bar" style="background-color: #ed8089; height: 20px; width: 100px"></div>
                  <div class="label">已冻结</div>
                </div>
                <div class="bar-container">
                  <div class="bar" style="background-color: #a9bfed; height: 20px;"></div>
                  <div class="label">有库存</div>
                </div>
              </div>
            </div>
            <el-col :span="1.5">
              <el-button
                type="danger"
                size="medium"
                :disabled="multiple"
                @click="clickIce(1)"
              >冻库位</el-button>
            </el-col>

            <el-col :span="1.5">
              <el-button
                type="success"
                size="medium"
                :disabled="multiple"
                @click="clickIce(0)"
              >可入库</el-button>
            </el-col>
          </el-form>

          <right-toolbar :showSearch.sync="showSearch"></right-toolbar>
        </el-row>
<!--        <div class="chart-container">-->
<!--          <div class="bar" style="background-color: #a4f3b7; height: 20px;">可入库</div>-->
<!--          <div class="bar" style="background-color: #ed8089; height: 20px;">已冻结</div>-->
<!--          <div class="bar" style="background-color: #a9bfed; height: 20px;">有库存</div>-->
<!--        </div>-->

        <el-card style="height: 750px;margin-top: 20px">

          <el-table border
                    ref="filterTable"  v-loading="loading" height="750px" :data="decidLOCATIONList" @cell-click="handleCellDblClick1"
                    @selection-change="handleSelectionChange1" :row-style="rowStyle" >
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column
              fixed
              type="index"
              label="行号"
              width="60"
              align="center"
            />
            <el-table-column  label="堆垛机编号" align="center" prop="decId"/>
            <el-table-column label="库位编号" align="center" prop="locationId"/>

            <el-table-column label="排" align="center" prop="row"/>
            <el-table-column label="列" align="center" prop="cln"/>
            <el-table-column label="层" align="center" prop="layer"/>

            <el-table-column label="深度" align="center" prop="deep"/>
            <el-table-column fixed="right" label="状态" align="center" prop="STATUS">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.kw_sts" :value="scope.row.status"/>
              </template>
            </el-table-column>
            <!--        <el-table-column label="助记码" align="center" prop="pyName" />-->
            <!--        <el-table-column label="仓库编号" align="center" prop="storageId" />-->
            <!--        <el-table-column label="ISLOCK" align="center" prop="ISLOCK" />-->
            <!--        <el-table-column label="长" align="center" prop="locationLong" />-->
            <!--        <el-table-column label="宽" align="center" prop="locationWidth" />-->
            <!--        <el-table-column label="高" align="center" prop="locationHeight" />-->
            <!--        <el-table-column label="体积" align="center" prop="VOLUME" />-->
            <!--        <el-table-column label="HASVOLUME" align="center" prop="HASVOLUME" />-->
            <!--        <el-table-column label="承重" align="center" prop="BEARWEIGHT" />-->
            <!--        <el-table-column label="abc分类" align="center" prop="abcId" />-->
            <!--        <el-table-column label="排序" align="center" prop="SORT" />-->
            <!--        <el-table-column label="状态" align="center" prop="STATUS">-->
            <!--          <template slot-scope="scope">-->
            <!--            <dict-tag :options="dict.type.status" :value="scope.row.STATUS"/>-->
            <!--          </template>-->
            <!--        </el-table-column>-->
            <!--        <el-table-column label="备注" align="center" prop="REMARK" />-->
            <!--        <el-table-column label="版本" align="center" prop="VERSION" />-->
            <!--        <el-table-column label="操作人" align="center" prop="OPERATORID" />-->
            <!--        <el-table-column label="操作时间" align="center" prop="OPERATEDATE" width="180">-->
            <!--          <template slot-scope="scope">-->
            <!--            <span>{{ parseTime(scope.row.OPERATEDATE, '{y}-{m}-{d}') }}</span>-->
            <!--          </template>-->
            <!--        </el-table-column>-->


            <!--                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
            <!--                    <template slot-scope="scope">-->
            <!--                      <el-button-->
            <!--                        size="mini"-->
            <!--                        type="text"-->
            <!--                        icon="el-icon-edit"-->
            <!--                        @click="handleUpdate(scope.row)"-->
            <!--                        v-hasPermi="['system:LOCATION:edit']"-->
            <!--                      >修改-->
            <!--                      </el-button>-->
            <!--                      <el-button-->
            <!--                        size="mini"-->
            <!--                        type="text"-->
            <!--                        icon="el-icon-delete"-->
            <!--                        @click="handleDelete(scope.row)"-->
            <!--                        v-hasPermi="['system:LOCATION:remove']"-->
            <!--                      >删除-->
            <!--                      </el-button>-->
            <!--                    </template>-->
            <!--                  </el-table-column>-->
          </el-table>
<!--          <pagination-->
<!--            v-show="total>0"-->
<!--            :total="total"-->
<!--            :page.sync="queryParams.pageNum"-->
<!--            :limit.sync="queryParams.pageSize"-->
<!--            @pagination="handlePaginationChange"-->
<!--          />-->
        </el-card>



        <el-row style="margin-top: 20px">
          <el-col :span="24">
            <el-card style="height: 150px;">
              <el-table v-loading="loading" height="400px" :data="LocationIDLOCATIONList" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" align="center"/>
                <el-table-column
                  fixed
                  type="index"
                  label="行号"
                  width="60"
                  align="center"
                />
<!--                <el-table-column sortable fixed label="库存编号" align="center" prop="stockId"/>-->
                <el-table-column label="入库单号" align="center" prop="putinId"/>
                <el-table-column label="库位编号" align="center" prop="locationId"/>
                <el-table-column label="托盘号" align="center" prop="ctl" />
                <el-table-column label="物料编号" align="center" prop="goodsId"/>
                <el-table-column label="数量" align="center" prop="shelvesNum"/>
                <el-table-column label="上架时间" align="center" prop="wareDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.wareDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
              </el-table>
            </el-card>
          </el-col>
        </el-row>

        <!-- 添加或修改库位管理对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="库位编号" prop="locationId">
              <el-input v-model="form.locationId" placeholder="请输入库位编号"/>
            </el-form-item>
            <el-form-item label="助记码" prop="pyName">
              <el-input v-model="form.pyName" placeholder="请输入助记码"/>
            </el-form-item>
            <el-form-item label="仓库编号" prop="storageId">
              <el-input v-model="form.storageId" placeholder="请输入仓库编号"/>
            </el-form-item>
            <el-form-item label="ISLOCK" prop="ISLOCK">
              <el-input v-model="form.ISLOCK" placeholder="请输入ISLOCK"/>
            </el-form-item>
            <el-form-item label="abc分类" prop="abcId">
              <el-input v-model="form.abcId" placeholder="请输入abc分类"/>
            </el-form-item>
            <el-form-item label="状态" prop="STATUS">
              <el-select v-model="form.STATUS" placeholder="请选择状态">
                <el-option
                  v-for="dict in dict.type.status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="备注" prop="REMARK">
              <el-input v-model="form.REMARK" placeholder="请输入备注"/>
            </el-form-item>
            <el-form-item label="版本" prop="VERSION">
              <el-input v-model="form.VERSION" placeholder="请输入版本"/>
            </el-form-item>
            <el-form-item label="操作人" prop="OPERATORID">
              <el-input v-model="form.OPERATORID" placeholder="请输入操作人"/>
            </el-form-item>
            <el-form-item label="操作时间" prop="OPERATEDATE">
              <el-date-picker clearable
                              v-model="form.OPERATEDATE"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择操作时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="堆垛机编号" prop="decId">
              <el-input v-model="form.decId" placeholder="请输入堆垛机编号"/>
            </el-form-item>
            <el-form-item label="入库站台" prop="instand">
              <el-input v-model="form.instand" placeholder="请输入入库站台"/>
            </el-form-item>
            <el-form-item label="出库站台" prop="outStand">
              <el-input v-model="form.outStand" placeholder="请输入出库站台"/>
            </el-form-item>
            <el-form-item label="入库输送线" prop="inline">
              <el-input v-model="form.inline" placeholder="请输入入库输送线"/>
            </el-form-item>
            <el-form-item label="出库输送线" prop="outLine">
              <el-input v-model="form.outLine" placeholder="请输入出库输送线"/>
            </el-form-item>
            <el-form-item label="行" prop="row">
              <el-input v-model="form.row" placeholder="请输入行"/>
            </el-form-item>
            <el-form-item label="列" prop="cln">
              <el-input v-model="form.cln" placeholder="请输入列"/>
            </el-form-item>
            <el-form-item label="层级" prop="layer">
              <el-input v-model="form.layer" placeholder="请输入层级"/>
            </el-form-item>
            <el-form-item label="入库站台1" prop="instand1">
              <el-input v-model="form.instand1" placeholder="请输入入库站台1"/>
            </el-form-item>
            <el-form-item label="入库站台2" prop="instand2">
              <el-input v-model="form.instand2" placeholder="请输入入库站台2"/>
            </el-form-item>
            <el-form-item label="出库站台1" prop="outStand1">
              <el-input v-model="form.outStand1" placeholder="请输入出库站台1"/>
            </el-form-item>
            <el-form-item label="入库站台3" prop="instand3">
              <el-input v-model="form.instand3" placeholder="请输入入库站台3"/>
            </el-form-item>
            <el-form-item label="出库站台2" prop="outStand2">
              <el-input v-model="form.outStand2" placeholder="请输入出库站台2"/>
            </el-form-item>
            <el-form-item label="出库站台11" prop="outStand11">
              <el-input v-model="form.outStand11" placeholder="请输入出库站台11"/>
            </el-form-item>
            <el-form-item label="深度" prop="deep">
              <el-input v-model="form.deep" placeholder="请输入深度"/>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
      </el-col>
    </el-row>
  </div>
</template>
<style>
.float-right-container {
  float: right; /* 容器向右浮动 */
  clear: both; /* 清除浮动，避免影响后续元素 */
}
.chart-container {
  display: flex;
  align-items: center; /* 使所有条形图和标签垂直居中 */
  gap: 10px; /* 条形图之间的间隔 */
}

.bar-container {
  display: flex;
  flex-direction: column;
  align-items: center; /* 使条形图和标签水平居中 */
}

.bar {
  width: 100px; /* 假设条形图的宽度为50px */
  margin-bottom: 5px; /* 条形图和标签之间的间隔 */
}

.label {
  font-size: 14px; /* 标签的字体大小 */
  color: #333; /* 标签的文字颜色 */
}
</style>
<script>
import {
  listLOCATION,
  getLOCATION,
  delLOCATION,
  addLOCATION,
  updateLOCATION,
  selelectLOCATIONBYdecId, loselelectSTOCKBYlocationId,updateSts
} from "@/api/system/location";
import {selelectSTOCKBYlocationId} from "@/api/system/stock";
import { listDecname } from "@/api/system/decname";



export default {
  name: "LOCATION",
  dicts: ['kw_sts','status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 库位管理表格数据
      LOCATIONList: [],
      decidLOCATIONList: [],
      LocationIDLOCATIONList: [],
      delDecnameList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      decidqueryParams: {
        pageNum: null,
        pageSize: null,
        decid: null,
        decname: null,
        sts: null,
        taskName: null,
        taskId: null,
        ct: null,
        storageId: null,
        size: null,
        nowPlcid: null,
        autoModel: null,
        rowl: null,
        clm: null,
        lyr: null,
        error: null,
        plcDB: null,
        decSts: null
      },
      // 查询参数
      queryParams: {
        pageNum: null,
        pageSize: null,
        locationId: null,
        pyName: null,
        storageId: null,
        ISLOCK: null,
        locationLong: null,
        locationWidth: null,
        locationHeight: null,
        VOLUME: null,
        HASVOLUME: null,
        BEARWEIGHT: null,
        abcId: null,
        SORT: null,
        STATUS: null,
        REMARK: null,
        VERSION: null,
        OPERATORID: null,
        OPERATEDATE: null,
        decId: null,
        instand: null,
        outStand: null,
        inline: null,
        outLine: null,
        row: null,
        cln: null,
        layer: null,
        instand1: null,
        instand2: null,
        outStand1: null,
        instand3: null,
        outStand2: null,
        outStand11: null,
        deep: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        locationId: [
          {required: true, message: "库位编号不能为空", trigger: "blur"}
        ],
        storageId: [
          {required: true, message: "仓库编号不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList2();
    this.getList3();
  },

  methods: {
    clickIce(con){
      this.form.STATUS = con
      updateSts({locationId:this.locationId,status: this.form.STATUS}).then(response => {+
        this.handlePaginationChange();
        this.dialogVisible = false;
      });
    },
    handleCellDblClick(row, column, cell, event) {
      this.loading = true;
      this.queryParams.decId = row.decid
      selelectLOCATIONBYdecId(this.queryParams).then(response => {
        this.decidLOCATIONList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.decId = row.decid;
      });
    },
    handleCellDblClick1(row, column, cell, event) {
      this.loading = true;
      selelectSTOCKBYlocationId(row.locationId).then(response => {
        this.LocationIDLOCATIONList = response.rows;
        this.loading = false;
      });
    },
    handlePaginationChange() {
      this.loading = true;
      selelectLOCATIONBYdecId(this.queryParams).then(response => {
        this.decidLOCATIONList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询库位管理列表 */
    // getList() {
    //   this.loading = true;
    //   listLOCATION(this.queryParams).then(response => {
    //     this.LOCATIONList = response.rows;
    //     this.total = response.total;
    //     this.loading = false;
    //   });
    // },
    getList1() {
      // this.loading = true;
      // loselelectSTOCKBYlocationId(this.queryParams.locationId).then(response => {
      //   this.decidLOCATIONList = response.rows;
      //   this.total = response.total;
      //   this.loading = false;
      // });
      this.loading = true;
      listLOCATION(this.queryParams).then(response => {
        this.decidLOCATIONList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getList2() {
      this.loading = true;
      listDecname(this.decidqueryParams).then(response => {
        this.delDecnameList = response.rows;
        // this.total = response.total;
        this.loading = false;
      });
    },
    getList3() {
      this.loading = true;
      this.queryParams.decId= "1";
      selelectLOCATIONBYdecId(this.queryParams).then(response => {
          this.decidLOCATIONList = response.rows;
          this.total = response.total;
          this.loading = false;
          this.decId ="1";
      }
      );
      // this.handlePaginationChange();
    },
    rowStyle({row, rowIndex}) {
      if (row.status === '0') {
        return {backgroundColor: '#a4f3b7'};
      } else if (row.status === '1') {
        return {backgroundColor: '#ed8089'};
      }else if (row.status === '2') {
        return {backgroundColor: '#a9bfed'};
      }
      return '';
    },
  // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        locationId: null,
        pyName: null,
        storageId: null,
        ISLOCK: null,
        locationLong: null,
        locationWidth: null,
        locationHeight: null,
        VOLUME: null,
        HASVOLUME: null,
        BEARWEIGHT: null,
        abcId: null,
        SORT: null,
        STATUS: null,
        REMARK: null,
        VERSION: null,
        OPERATORID: null,
        OPERATEDATE: null,
        decId: null,
        instand: null,
        outStand: null,
        inline: null,
        outLine: null,
        row: null,
        cln: null,
        layer: null,
        instand1: null,
        instand2: null,
        outStand1: null,
        instand3: null,
        outStand2: null,
        outStand11: null,
        deep: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // this.queryParams.pageNum = 1;
      this.getList();
    },
    handleQuery1() {
      // this.queryParams.pageNum = 1;
      this.getList1();
    },
    handleQuery2() {
      // this.decidqueryParams.pageNum = 1;
      this.getList2();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    resetQuery1() {
      this.handlePaginationChange();
      this.queryParams.STATUS=null;
    },
    resetQuery2() {
      this.handleQuery2();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.locationId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleSelectionChange1(selection) {
      this.locationId = selection.map(item => item.locationId)
      this.ids = selection.map(item => item.locationId)
      this.single = selection.length !== 1
      this.multiple = !selection.length

    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加库位管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const locationId = row.locationId || this.ids
      getLOCATION(locationId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改库位管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          debugger
          if (this.form.locationId != null) {
            updateLOCATION(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLOCATION(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const locationIds = row.locationId || this.ids;
      this.$modal.confirm('是否确认删除库位管理编号为"' + locationIds + '"的数据项？').then(function () {
        return delLOCATION(locationIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/LOCATION/export', {
        ...this.queryParams
      }, `LOCATION_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

